from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline

# 加载模型和分词器
model_name = "facebook/bart-large-cnn"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)

# 创建 pipeline
summarizer = pipeline('summarization', model=model, tokenizer=tokenizer)

# 测试
text = """
In a world of increasing complexity, the importance of having access to high-quality and reliable information cannot be overstated.
With the proliferation of data and information, the need for systems that can process and make sense of that information
has become more critical than ever. AI-based tools and technologies are increasingly playing a central role in enabling
people and organizations to make data-driven decisions and insights that can lead to more informed choices.
"""
summary = summarizer(text, max_length=50, min_length=25, do_sample=False)
print(summary)
